﻿using System.Linq.Expressions;

namespace MyDapperApi.Repositories.Interfaces;

public interface IRepository<T> where T : class
{
    Task<T?> GetByIdAsync(int id);
    Task<T?> GetByIdAsync(string id); // 支持字符串主键
    Task<IEnumerable<T>> GetAllAsync();
    Task<IEnumerable<T>> FindAsync(Expression<Func<T, bool>> predicate);
    Task<T?> FirstOrDefaultAsync(Expression<Func<T, bool>> predicate);
    Task<int> AddAsync(T entity);
    Task<int> UpdateAsync(T entity);
    Task<int> DeleteAsync(int id);
    Task<int> DeleteAsync(string id);
    Task<int> CountAsync(Expression<Func<T, bool>> predicate = null);
    Task<bool> ExistsAsync(Expression<Func<T, bool>> predicate);
}